<template>
  <div>
    <div class="title">
      <van-icon name="arrow-left" @click="$router.go(-1)"/>
      <span>添加收货地址</span>
    </div>
    <van-address-edit
        show-delete
        show-set-default
        show-search-result
        :area-list="areaList"
        :area-columns-placeholder="['请选择', '请选择', '请选择']"
        @save="onSave"
        @delete="onDelete"
        @change-detail="onChangeDetail"
        @change-area="onChangeAddress">
    </van-address-edit>
  </div>
</template>

<script>
import {areaList} from '@vant/area-data'

export default {
  name: "AdditionAdd",
  data() {
    return {
      province: '',
      city: '',
      county: '',
      code: null, // 选中的地区编码
      areaList
    }
  },
  methods: {
    async onSave(content) {
      console.log(content)
      const save = await this.$post('address/save', {
        name: content.name,
        tel: content.tel,
        province: content.province,
        city: content.city,
        county: content.county,
        addressDetail: content.addressDetail,
        isDefault: content.isDefault
      })
      console.log(save)
      this.$router.go(-1)
    },
    onDelete() {
      // Toast('delete');
    },
    onChangeDetail(val) {
      // console.log(val)
    },
    onChangeAddress(values) {
      console.log(values)
    }
  }
}
</script>

<style lang="less" scoped>
.title {
  position: relative;
  width: 375px;
  height: 45px;
  line-height: 45px;
  font-size: 18px;
  text-align: center;

  .van-icon-arrow-left {
    position: absolute;
    left: 0px;
    line-height: 45px;
    margin-left: 11px;
    font-size: 18px;
  }
}


</style>
